package com.wancaijinfu.ui.index1;



import java.util.HashMap;
import java.util.Map;

import com.wancaijinfu.actitvity.R;
import com.wancaijinfu.constant.Url;
import com.wancaijinfu.javabean.Debt;
import com.wancaijinfu.parse.DebtListParse;
import com.wancaijinfu.widget.MActionBar;
import com.wancaijinfu.widget.PullListBaseFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class DebtFragment extends PullListBaseFragment {
	
	
	//private String type;
	
	public static DebtFragment newInstantce() {
		DebtFragment fragment = new DebtFragment();
		//Bundle bundle = new Bundle();
		//bundle.putSerializable("type", type);
		//fragment.setArguments(bundle);
		return fragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//category = (PINGDAO) getArguments().getSerializable("PINGDAO");
		//type =  (String) getArguments().getSerializable("type");
	}
	
	@Override
	public void setMTitle(MActionBar actionBar) {
//		if (category == PINGDAO.YUJING) tag = WARNING;
//		else if (category == PINGDAO.ZIXUN) tag = NEWS;
		actionBar.setDiabled();
	}
	
	
	@Override
	public void getUIData() {
		Map<String, String> params = new HashMap<String, String>();
		
		
		//params.put("name", username);
		//params.put("password", MD5Encoding.getMD5(password));
		//Params params = Params.getInstance().add("type", 1);
		String requestURL = Url.TEST_SERVER+"api2/debtList.action";
			getNetData(requestURL, params, new DebtListParse());
	}
	
	
//	@Override
//	public View getListHeader() {
//		//View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_list_footer, null);
//		return null;
//	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	
	static class ViewHolder {
		public TextView trans_money;
		public TextView discount;
		public TextView interest;
		public TextView debt_name;
		public ImageView sold_out;
		public TextView transfer;
		
	}

	@Override
	public View bindViewItem(int position, View convertView, ViewGroup parent,
			Object object) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(getActivity()).inflate(
					R.layout.debt_item, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.trans_money = (TextView) convertView
					.findViewById(R.id.trans_money);
			viewHolder.discount = (TextView) convertView
					.findViewById(R.id.discount);
			viewHolder.interest = (TextView) convertView
					.findViewById(R.id.interest);
			viewHolder.debt_name = (TextView) convertView
			.findViewById(R.id.debt_name);
			
			viewHolder.transfer = (TextView) convertView
					.findViewById(R.id.transfer);
			
			viewHolder.sold_out = (ImageView) convertView
					.findViewById(R.id.sold_out);
			
			
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		final Debt data = (Debt) object;
		convertView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(),
						DebtDoActivity.class);
				intent.putExtra("debt", data);
				startActivity(intent);
			}
		});
		

		//viewHolder.view.setProcess((int)(data.account_yes/data.account*100),textStatus);
		
		viewHolder.trans_money.setText(data.money+"");
		viewHolder.discount.setText(data.discount+"%");
		viewHolder.interest.setText(data.interest+"");
		if(data.status==1){
			viewHolder.sold_out.setVisibility(View.GONE);
		}
		viewHolder.debt_name.setText(data.name);
		viewHolder.transfer.setText(data.user_name);
		
		return convertView;
	}

	

	

}
